package PyroBots.Controlleur;

import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;
import PyroBots.Modele.Case;
import PyroBots.Modele.Terrain;
import PyroBots.Vue.VueTerrain;

public class CTerrain implements Serializable {

	private Terrain terrain;
	private VueTerrain vueTerrain;
	private boolean carteChargee = false;
	
	public boolean isCarteChargee() {
		return carteChargee;
	}
	
	public void setCarteChargee(boolean carteChargee) {
		this.carteChargee = carteChargee;
	}

	

	public CTerrain ()
	{
		terrain = new Terrain(500);
		Set<Case> cases = new HashSet<Case>();
		Case depart = null;
		Case arrivee = null;

		for(int i = 0 ; i<500; i++){
			for(int k = 0 ; k<500; k++){
				if(i==0 && k == 0){
					depart= new Case(1,i,k,terrain);
					cases.add(depart);
				}
				else if(i==45 && k==450){
					arrivee= new Case(1,i,k,terrain);
					cases.add(arrivee);
				}
				else{
					if(i == 2 && k != 49)
						cases.add(new Case(100,i,k,terrain));
					else
						cases.add(new Case(1,i,k,terrain));
				}
			}
		}
		terrain.setCases(cases);
		terrain.setcTerrain(this);
	}
	/** 
	 * @return terrain
	 */

	public void setVueTerrain(VueTerrain p_vueTerrain)
	{
		vueTerrain = p_vueTerrain;
	}

	public VueTerrain getVueTerrain()
	{
		return vueTerrain;
	}

	public Terrain getTerrain() {
		return terrain;
	}

	/** 
	 * @param terrain
	 */
	public void setTerrain(Terrain terrain) {
		this.setCarteChargee(true);
		this.vueTerrain.getParent().getJP_VueFlotte().getjButton_feu().notifyCarte(this);
		this.vueTerrain.getParent().getJP_VueSimu().getjButton_play().notifyCarte(this);
		this.terrain = terrain;
	}
}